<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<% String invoice_id=request.getParameter("invoice_id"); %>
<html>
	<head>
		<title>项目收款管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"项目付款管理(实际金额=支付金额-借款金额)",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMPayment?flagType=1',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'项目id',field:'xm_id',hidden:true},
				    {title:'分包商id',field:'pay_to_id',hidden:true}
				]],
				columns:[[
					{title:'创建时间',field:'operation_time',width:100,align:'center'},
					{title:'部门',field:'dept_name',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:100,align:'center'},
					{title:'支付对象',field:'pay_to_name',width:100,align:'center'},
					{title:'对象类型',field:'pay_type',width:80,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "分包商";
						}
						return "未知";
					}},
					{title:'实际金额',field:'pay_value',width:50,align:'center'},
					{title:'支付金额',field:'payValue',width:50,align:'center',formatter:function(value,rowData,rowIndex){
						return rowData.pay_value+rowData.cut_payment;
					}},
					{title:'扣借款金额',field:'cut_payment',width:100,align:'center'},
					{title:'摘要',field:'remark',width:100,align:'center'},
					{title:'审核状态',field:'status',width:80,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'详情操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"','"+rowData.xm_id+"');\"/> &nbsp;&nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"',"+rowData.pay_type+",'"+rowData.xm_id+"');\"/> &nbsp;&nbsp;";
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteData('"+rowData.id+"');\"/>";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>' ){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:editXMInvoice('"+rowData.id+"','"+rowData.xm_id+"');\"/> &nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_PAYMENT_SHIGONG_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
						}
						if(rowData.status == '<%=com.beaut.project.util.StaticData.PASS%>'||rowData.status == '<%=com.beaut.project.util.StaticData.AUDITING%>'){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_PAYMENT_SHIGONG_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewData('"+rowData.id+"',"+rowData.pay_type+",'"+rowData.xm_id+"');\"/>";
						}
	                    	return str;
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
        function addSupplyPayment(){
        	 //var para="xm_id="+id+"&xm_code="+encodeURIComponent(xm_code)+"&xm_name="+encodeURIComponent(xm_name)+"&dept_id="+dept_id+"&dept_name="+encodeURIComponent(dept_name)+"&customer_id="+customer_id+"&customer="+encodeURIComponent(customer);
        	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditSupplyPayment.jsp?callback=rtCallBack",1000, 800);
        }
        
        function addWorkerPayment(){
        	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditWorkerPayment.jsp?callback=rtCallBack",1000, 800);
        }
		function shenpi(obj,id,type,xm_id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	    	var flowBusinessUrl="#";
	    	var param="";
	     if(type==2){
	      flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditSupplyPayment.jsp?id="+id+"&xm_id="+xm_id+"&isShow=1";
	       param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_PAYMENT_SHENPI%>")+"&businessId="+id;
	      
	     }else{
	     flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditWorkerPayment.jsp?id="+id+"&xm_id="+xm_id+"&isShow=1";
	     param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_PAYMENT_SHIGONG_SHENPI%>")+"&businessId="+id;
	     }
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		
		function deleteData(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/deleteXMPayment",
						data:"id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}

		function  editXMInvoice(id,xm_id){
		    openDialogResize("<%=contextPath %>/springViews/xm/addOrEditWorkerPayment.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=0",1000, 800);
		}
		function  viewData(id,type,xm_id){
		 if(type==1){
		 	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditWorkerPayment.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=1",1000, 800);
		 }else{
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditSupplyPayment.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=1",1000, 800);
		}
	
		}

		function rtCallBack(){
			$('#table').datagrid('reload');
		}

		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				start_time:start_time,
				dept_id : dept_id,
				end_time:end_time
				
			});
		}
		function  jsRate(rowData){
			var date=new Date();
	        var year = date.getFullYear();       //年
	        var month = date.getMonth() + 1;     //月
	        var day = date.getDate();            //日
			var operation_date=year+"-"+month+"-"+day;
			var dates=0;
			if(0==date.getYear()%4&&((date.getYear()%100!=0)||(date.getYear()%400==0))){
				dates=366;
			}else{
				dates=365;
			}
			var dateNum=0;
			var lxMoney=0;
			var oneTime=operation_date;
			var twoTime=rowData.actual_operation_date.split(" ");
			dateNum=getDays(oneTime,twoTime[0]);
			if(parseFloat(rowData.on_money)==0){
				lxMoney=parseFloat(rowData.money*rowData.rate*dateNum/(100*dates)).toFixed(2);//利息
			}else{
				lxMoney=parseFloat(rowData.on_money*rowData.rate*dateNum/(100*dates)).toFixed(2);//利息
			}
			return lxMoney;
		}
	</script>
		<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<!-- <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addSupplyPayment(0);">新增采购支付</a> -->
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addWorkerPayment(0);">新增分包款支付</a>
			</div>
			<div align="right">
				所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px"/>&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px"/>
				项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目编号/名称" placeholder="项目编号/名称 "  />&nbsp;&nbsp; 
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>